/* 
 * File:   main.c
 * Author: frank
 *
 * Created on February 22, 2015, 9:55 AM
 */

#include <stdio.h>
#include <stdlib.h>
#include "PS2Protocol.h"

#pragma config FNOSC    = PRIPLL        // Oscillator Selection
#pragma config POSCMOD  = EC            // Primary Oscillator
#pragma config OSCIOFNC = OFF           // CLKO Enable
// 8 Mhz
#pragma config UPLLIDIV = DIV_2         // USB PLL Input Divider
#pragma config FPLLIDIV = DIV_2         // PLL Input Divider
// Other
#pragma config UPLLEN   = ON            // USB PLL Enabled
#pragma config FPLLMUL  = MUL_20        // PLL Multiplier
#pragma config FPLLODIV = DIV_2         // PLL Output Divider
#pragma config FPBDIV   = DIV_1         // Peripheral Clock divisor
#pragma config FWDTEN   = OFF           // Watchdog Timer
#pragma config WDTPS    = PS1           // Watchdog Timer Postscale
#pragma config FCKSM    = CSDCMD        // Clock Switching & Fail Safe Clock Monitor
#pragma config IESO     = OFF           // Internal/External Switch-over
#pragma config FSOSCEN  = OFF           // Secondary Oscillator Enable
#pragma config CP       = OFF           // Code Protect
#pragma config BWP      = OFF           // Boot Flash Write Protect
#pragma config PWP      = OFF           // Program Flash Write Protect
#pragma config ICESEL   = ICS_PGx1      // ICE/ICD Comm Channel Select
#pragma config DEBUG    = OFF           // Debugger Disabled for Starter Kit
#pragma config JTAGEN   = OFF           // No JTAG.  Need this for RB9 to work!

#define size 100
unsigned char data[size];
unsigned int index = 0;

void PS2P_Available_Int(){
    data[index++] = PS2_GetScanCode();
    if (index == size) index = 0;
}

int main(int argc, char** argv) {
    INTEnableSystemMultiVectoredInt();

    PS2_Init();
    PS2_AvailableCallback(PS2P_Available_Int);
    PS2_Send(0xFF);
    while(1){}
    return (EXIT_SUCCESS);
}

